﻿using System.Web.Http;
using ML.IBusiness;
using ML.Entity;

namespace ML.WebApi.Controllers
{
    /// <summary>
    /// 收货地址api接口
    /// </summary>
    [CrossSite]
    public class ReceivingAddressController : BaseApiController
    {
        private readonly IReceivingAddressBusiness receivingAddressBusiness;
        public ReceivingAddressController(IReceivingAddressBusiness _receivingAddressBusiness)
        {
            receivingAddressBusiness = _receivingAddressBusiness;
        }

        /// <summary>
        /// 前端已经在使用此接口—根据用户Id查询用户收货地址列表
        /// </summary>
        /// <param name="id">用户的id</param>
        /// <returns></returns>
        [Route("api/receivingaddress/getlistbyuserid")]
        [HttpGet]
        public IHttpActionResult GetListByUserId(string id)
        {
            var data = receivingAddressBusiness.GetListByUserId(id);
            return Json(data);
        }

        /// <summary>
        /// 前端已经在使用此接口—根据用户Id读取用户默认收货地址
        /// </summary>
        /// <param name="id">用户的id</param>
        /// <returns></returns>
        [Route("api/receivingaddress/getdefaultbyuserid")]
        [HttpGet]
        public IHttpActionResult GetDefaulByUserId(string id)
        {
            var data = receivingAddressBusiness.GetDefaulByUserId(id);
            return Json(data);
        }

        /// <summary>
        /// 前端已经在使用此接口—根据地址Id查询地址信息
        /// </summary>
        /// <param name="id">地址Id</param>
        /// <returns></returns>
        [Route("api/receivingaddress/getbyid")]
        [HttpGet]
        public IHttpActionResult GetById(string id)
        {
            var data = receivingAddressBusiness.getById(id);
            return Json(data);
        }

        /// <summary>
        /// 前端已经在使用此接口—添加用户收货地址(设置为默认)
        /// </summary>
        /// <param name="receivingAddressEntity">用户收货地址实体</param>
        /// <returns></returns>
        [Route("api/receivingaddress/add")]
        [HttpPost]
        public IHttpActionResult Add(ReceivingAddressEntity receivingAddressEntity)
        {
            var data = receivingAddressBusiness.Add(receivingAddressEntity);
            return Json(data);
        }

        /// <summary>
        /// 前端已经在使用此接口—修改用户收货地址
        /// </summary>
        /// <param name="receivingAddressEntity">用户收货地址实体</param>
        /// <returns></returns>
        [Route("api/receivingaddress/update")]
        [HttpPost]
        public IHttpActionResult Update(ReceivingAddressEntity receivingAddressEntity)
        {
            var data = receivingAddressBusiness.Update(receivingAddressEntity);
            return Json(data);
        }

        /// <summary>
        /// 删除用户收货地址
        /// </summary>
        /// <param name="id">用户收货地址Id</param>
        /// <returns></returns>
        [Route("api/receivingaddress/delete")]
        [HttpPost]
        public IHttpActionResult Delete(string id)
        {
            var data = receivingAddressBusiness.Delete(id);
            return Json(data);
        }

        /// <summary>
        /// 设置默认用户收货地址
        /// </summary>
        /// <param name="id">用户收货地址Id</param>
        /// <param name="userid">用户Id</param>
        /// <returns></returns>
        [Route("api/receivingaddress/default")]
        [HttpPost]
        public IHttpActionResult Default(string id, string userid)
        {
            var data = receivingAddressBusiness.Default(id, userid);
            return Json(data);
        }
    }
}